import {Welcome} from "../cms/Welcome";
import {GetServerSideProps, NextPage} from "next";
import {CmsPreviewApp} from "../cms/Preview";

const Page: NextPage = ({data}: any) => {
    return (
        <div>
            {!!data && <CmsPreviewApp data={data}/>}
            <Welcome/>
        </div>
    )
}

export default Page

export const getServerSideProps: GetServerSideProps = async (ctx) => {

    const id = ctx.query.code
    let data = null
    if (!!id) {
        const resp = await fetch('http://1.116.13.72:7001/cms/item', {
            method: 'post',
            body: JSON.stringify({id}),
            headers: {
                'content-type': 'application/json'
            },
        })
        data = JSON.parse((await resp.json()).result.json)
    }

    return {
        props: {
            data,
        },
    }
}